package com.huiquan.foundation.service;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huiquan.foundation.constant.CheckParamType;
import com.huiquan.foundation.dao.CheckParamDao;
import com.huiquan.foundation.domain.CheckParam;
import com.huiquan.framework.base.BaseService;

@Service
public class CheckParamService extends BaseService {
	@Autowired
	private CheckParamDao checkParamDao;

	public String getParamByType(CheckParamType type) {
		Map<String, Object> map = new HashMap<>();
		map.put("type", type.getId());

		CheckParam cp = checkParamDao.retrieveObjectByMap(map);
		if (cp != null) {
			return cp.getParam();
		} else {
			return null;
		}
	}

	public void add(CheckParamType type, String param, String desc) {

		CheckParam cp = new CheckParam();
		cp.setType(type.getId());
		cp.setParam(param);
		cp.setDescription(desc);

		checkParamDao.insert(cp);
	}

	public void updateParamByType(CheckParamType type, String param) {

		CheckParam cp = new CheckParam();
		cp.setType(type.getId());
		cp.setParam(param);

		checkParamDao.update(cp);
	}
}
